package com.csx.governance.sample.consumerC.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * @author cuisongxu
 * @date 2023/4/2 18:34
 */
@RequestMapping("/consumerC")
@RestController
public class ConsumerCController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private Registration registration;

    @GetMapping("/test")
    public String test() {
        Map<String, String> metadata = registration.getMetadata();
        String host = registration.getHost();
        int port = registration.getPort();
        String instanceInfo = host + ":" + port + "  metadata: " + metadata.toString();
        return "consumerC " + instanceInfo;
    }

    /**
     * 这个是提供方,与test接口逻辑相同
     * @return
     */
    @GetMapping("/testFeign")
    public String testFeign() {
        Map<String, String> metadata = registration.getMetadata();
        String host = registration.getHost();
        int port = registration.getPort();
        String instanceInfo = host + ":" + port + "  metadata: " + metadata.toString();
        return "consumerC openfeign " + instanceInfo;
    }
}
